package cn.hushi.test;

import cn.hushi.domain.Customer;
import cn.hushi.utils.HibernateUtil;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Demo2 {
    public static void main(String[] args) {
        Demo2 demo1 = new Demo2();
        demo1.test1();
    }
        public void test1(){
            Customer customer =new Customer();
//            customer.setId(1);
            customer.setName("sian");
            customer.setAge(40);
            customer.setGender("男");
            customer.setLevel("VIP客户");

//            //读取hibernate配置文件
//            Configuration cfg = new Configuration().configure();
//
//            //创建SessionFactory工厂
//            SessionFactory factory = cfg.buildSessionFactory();
//
            //创建Session对象
            Session session = HibernateUtil.getSession();

            //开启事务
            Transaction tx = session.beginTransaction();

            //执行添加操作
            session.save(customer);

            //提交事务
            tx.commit();

            //关闭资源
            session.close();

        }
}